import type { Metadata } from "next" import { createSupabaseAdminClient } from "@/lib/supabase/admin" import { sanitizeEntryContent } from "@/lib/sanitize" interface SharedPageProperties { params: Promise<{ token: string }> } interface SharedEntryRow { entry_id: string expires_at: string | null entries: { id: string title: string | null url: string | null author: string | null summary: string | null content_html: string | null published_at: string | null enclosure_url: string | null feeds: { title: string | null } } } async function fetchSharedEntry(token: string) { const adminClient = createSupabaseAdminClient() const { data, error } = await adminClient .from("shared_entries") .select( "entry_id, expires_at, entries!inner(id, title, url, author, summary, content_html, published_at, enclosure_url, feeds!inner(title))" ) .eq("share_token", token) .maybeSingle() if (error || !data) return null const row = data as unknown as SharedEntryRow if (row.expires_at && new Date(row.expires_at) < new Date()) { return { expired: true as const } } return { expired: false as const, entry: row.entries } } export async function generateMetadata({ params, }: SharedPageProperties): Promise { const { token } = await params const result = await fetchSharedEntry(token) if (!result || result.expired) { return { title: "shared entry — asa.news" } } return { title: `${result.entry.title ?? "untitled"} — asa.news`, description: result.entry.summary?.slice(0, 200) ?? undefined, openGraph: { title: result.entry.title ?? "shared entry", description: result.entry.summary?.slice(0, 200) ?? undefined, siteName: "asa.news", }, } } function SanitisedContent({ htmlContent }: { htmlContent: string }) { // Content is sanitised via sanitize-html before rendering const sanitisedHtml = sanitizeEntryContent(htmlContent) return (
) } export default async function SharedPage({ params }: SharedPageProperties) { const { token } = await params const result = await fetchSharedEntry(token) if (!result) { return (

shared entry not found

this shared link is no longer available or has been removed.

) } if (result.expired) { return (

this share has expired

shared links expire after a set period. the owner may share it again if needed.

) } const entry = result.entry const formattedDate = entry.published_at ? new Date(entry.published_at).toLocaleDateString("en-GB", { day: "numeric", month: "long", year: "numeric", }) : null return (

{entry.title}

{entry.feeds?.title && {entry.feeds.title}} {entry.author && · {entry.author}} {formattedDate && · {formattedDate}}
{entry.enclosure_url && (
)}
) }